//=============================================================================
// TF Warpblade Shift Fire
//=============================================================================
class TFWBShiftFire extends WeaponFire;

var bool bShifted;
var TFWBShiftCloud cloud;
var TFWBShiftGlow glow;
var float lastammo;
var() int ShiftStartAmmo;



/*replication
{
    reliable if ( bNetOwner && (ROLE==ROLE_Authority) )
        lastammo, bShifted;
}*/

function PostBeginPlay()
{
	Super.PostBeginPlay();
	settimer(0.1,true);
}

simulated function timer()
{
    if(weapon.ammoamount(1)<=1) bIsFiring=false;
    if(!bIsFiring && weapon.ammoamount(1)<100) weapon.AddAmmo(1,1);
}

state Shift
{
    function BeginState()
    {
        lastammo=level.TimeSeconds;


        if(!bShifted)
        {
            Weapon.PlayOwnedSound(Sound'TFMedia.tfwbshift',SLOT_Interact,4);
            bShifted=true;
            if(tfpri(instigator.PlayerReplicationInfo)!=none) tfpri(instigator.PlayerReplicationInfo).Shifted=true;
            else DoShift(3);

            spawn(class'Taskforces.TFWBShiftSphere',instigator,,instigator.location).setbase(instigator);
            spawn(class'Taskforces.TFWBShiftFlash',instigator,,instigator.location);
            cloud=spawn(class'Taskforces.TFWBShiftCloud',instigator,,instigator.location + vect(0, 0, 10));
            glow=spawn(class'Taskforces.TFWBShiftGlow',instigator,,instigator.location);

            Instigator.AmbientSound=sound'TFMedia.tfwbshifted';
            playercontroller(Instigator.controller).SetFov(120);
            if ( glow != None )
	    	{
	    	    glow.Emitters[0].SkeletalMeshActor = instigator;
	    	    glow.SetLocation(instigator.Location - vect(0, 0, 49));
		        glow.SetRotation(instigator.Rotation + rot(0, -16384, 0));
		        glow.SetBase(instigator);
		    }
		    instigator.Controller.GotoState('PlayerFlying');
        }
    }

    function DoShift(float factor)
    {
        if(instigator.InCurrentCombo()) instigator.controller.adrenaline=0;
        instigator.airspeed=instigator.default.airspeed*factor;
	    instigator.accelrate=instigator.default.accelrate*factor;
        instigator.groundspeed=instigator.default.groundspeed*factor;
	    instigator.waterspeed=instigator.default.waterspeed*factor;
        instigator.aircontrol=instigator.default.aircontrol*factor;
    }

    function ModeTick(float tick)
    {
        if(!bIsFiring || !weapon.HasAmmo())
        {
            instigator.Controller.bAltFire=0;
            StopFiring();
        }
        else if(level.TimeSeconds>=lastammo+0.05)
        {
            Weapon.ConsumeAmmo(1,2);
            lastammo=level.TimeSeconds;
        }
    }

    function StopFiring()
    {
        if(bShifted)
        {
            spawn(class'Taskforces.TFWBUnshiftvortex',instigator,,instigator.location);
            spawn(class'Taskforces.TFWBShiftFlash',instigator,,instigator.location);

            Weapon.PlayOwnedSound(Sound'TFMedia.tfwbunshift',SLOT_Interact,4);
            bShifted=false;
            if(tfpri(instigator.PlayerReplicationInfo)!=none) tfpri(instigator.PlayerReplicationInfo).Shifted=false;
            else DoShift(1);
            if(cloud!=none) cloud.mRegen=false;
            if(glow!=none) glow.Destroy();
            Instigator.AmbientSound=none;
            instigator.Controller.GotoState('PlayerWalking');
            playercontroller(Instigator.controller).FixFov();
        }
        GotoState('');
    }

    function EndState()
    {
    }
}

function DoFireEffect()
{
}

function ModeHoldFire()
{
    GotoState('Shift');
}

defaultproperties
{
     bFireOnRelease=True
     FireAnim=
     FireEndAnim=
     FireAnimRate=0.500000
     AmmoClass=Class'Taskforces.TFWBShiftAmmo'
     BotRefireRate=0.300000
}
